Skip to content

Conversation

@jelaniwoods
Copy link
Contributor

@jelaniwoods jelaniwoods commented Jan 27, 2026

Resolves #50

This PR refactors the the proxy code to use the first-party openai-ruby gem with a different base url.

Additionally, I added an example for sending multiple system messages (which is allowed).

@jelaniwoods
Copy link
Contributor Author

🤔 test is failing consistently on CI but passing consistently locally.

@jelaniwoods jelaniwoods marked this pull request as ready for review January 28, 2026 19:56
@jelaniwoods
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

To use Codex here, create a Codex account and connect to github.

Comment on lines 157 to 163
def proxy=(value)
@proxy = value
@client = OpenAI::Client.new(
api_key: @api_key,
base_url: BASE_PROXY_URL
)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having some trouble understanding this method. Can you explain if and how it is used? It appears to be used when building the options Hash above? But I'm unsure, as this method here returns the OpenAI::Client, rather than a true / false as I would expect?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked claude, and it clarified for me that this is a setter as :proxy was moved from attr_accessor to attr_reader. I missed that above, now it makes sense!

While telling me this though, Claude made a suggestion that is worth considering:

File: lib/ai/chat.rb:157-163

def proxy=(value)
  @proxy = value
  @client = OpenAI::Client.new(
      api_key: @api_key,
      base_url: BASE_PROXY_URL
    )
end

The setter unconditionally creates a client with base_url: BASE_PROXY_URL regardless of whether value is true or false. Setting chat.proxy = false will still route all traffic through the proxy.

Suggested fix:

def proxy=(value)
  @proxy = value
  options = { api_key: @api_key }
  options[:base_url] = BASE_PROXY_URL if value
  @client = OpenAI::Client.new(**options)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a setter method for assigning the proxy attribute. When chat.proxy = true, this method runs and the @client must be updated with prepend.me as the base URL for all future requests. You raise a good point about the return value, even if it's not used used often.

On that note, it should toggle the base url when proxy is set to false too.

Copy link

@bpurinton bpurinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, are you planning to bump the gem version as well? Then I can proj syncing update our projects with the new version.

@jelaniwoods
Copy link
Contributor Author

LGTM, are you planning to bump the gem version as well? Then I can proj syncing update our projects with the new version.

I'm going to bump the gem version in a separate commit. I still need to update the API key validation.

@jelaniwoods jelaniwoods merged commit 647519f into main Jan 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-class issues related to Conversation endpoint changeover

3 participants